// mycomponent/Waterfalls_flow.js
var app = getApp();
Page({
  options: {
    styleIsolation: 'shared',
  },
  data:{
    clearable:true,
    listHeight:'',
    pagetype:'',
    placeholder:'',
    keyword:'',
    sjtotalPeople:0,
    sjtotalMoney:0,
    sjList:[],
    zltotalPeople:0,
    zltotalMoney:0,
    zl_zjtg_total:0,
    zl_jjtg_total:0,
    zlList:[],
    khtotalPeople:0,
    khtotalMoney:0,
    khList:[],
    offset:0,
    limit:10,
    page:0,
    tabIndex:1
  },
  tabClick(e){
    this.setData({
      page:0,
      offset:0,
      zlList:[],
      tabIndex:e.currentTarget.dataset.type
    })
    this.getListZL()
  },
  getHeight: function() {
    var query = wx.createSelectorQuery();
    query.select('#box').boundingClientRect(data => {
      if (data) {
        console.log(data.height); // 元素的高度
        let boxHeight = data.height
        // let windowHeight = wx.getSystemInfoSync().windowHeight
        this.setData({
          listPaddingHeight:boxHeight
        })
      }
    }).exec();
  },
  getListSJ(){
    let urlStr = app.getNetAddresss("plugin.company-manage.frontend.store.zhangLv.getMerchantsList");
    app._getNetWork({
      url: urlStr,
      data: {limit:this.data.limit,offset:this.data.offset,keyword:this.data.keyword},
      success: (resdata) => {
        console.log(resdata,'-----------resdata')
        if (resdata.data.result == 1) {
          this.setData({
            sjtotalPeople:resdata.data.data.count,
            sjtotalMoney:resdata.data.data.total_amount,
            sjList:this.data.sjList.concat(resdata.data.data.list)
          })
        }
      }
    })
  },
  getListZL(){
    let urlStr = app.getNetAddresss("plugin.company-manage.frontend.store.zhangLv.getPromoteZhanglvList");
    app._getNetWork({
      url: urlStr,
      data: {limit:this.data.limit,offset:this.data.offset,keyword:this.data.keyword,search_type:this.data.tabIndex},
      success: (resdata) => {
        console.log(resdata,'-----------resdata')
        if (resdata.data.result == 1) {
          this.setData({
            zltotalPeople:resdata.data.data.direct_push_count+resdata.data.data.indirect_push_count,
            zltotalMoney:resdata.data.data.total_amount,
            zl_zjtg_total:resdata.data.data.direct_push_count,
            zl_jjtg_total:resdata.data.data.indirect_push_count,
            zlList:this.data.zlList.concat(resdata.data.data.list)
          })
        }
      }
    })
  },
  getListKH(){
    let urlStr = app.getNetAddresss("plugin.company-manage.frontend.store.zhangLv.getPromoteCustomerList");
    app._getNetWork({
      url: urlStr,
      data: {limit:this.data.limit,offset:this.data.offset,keyword:this.data.keyword},
      success: (resdata) => {
        console.log(resdata,'-----------resdata')
        if (resdata.data.result == 1) {
          this.setData({
            khtotalPeople:resdata.data.data.count,
            khtotalMoney:resdata.data.data.total_amount,
            khList:this.data.khList.concat(resdata.data.data.list)
          })
        }
      }
    })
  },
  onChange(e){
    this.setData({
      keyword: e.detail,
    });
  },
  search(){
    console.log(this.data.keyword)
    if(this.data.pagetype == 1){
      this.setData({
        page:0,
        offset:0,
        zlList:[]
      })
      this.getListZL()
    } else if (this.data.pagetype == 2) {
      this.setData({
        page:0,
        offset:0,
        khList:[]
      })
      this.getListKH()
    } else {
      this.setData({
        page:0,
        offset:0,
        sjList:[]
      })
      this.getListSJ()
    }
  },
  onLoad(options){
    console.log(options)
    this.setData({
      pagetype:options.pagetype
    })
    if(this.data.pagetype == 1){
      this.setData({
        placeholder:'搜索掌旅姓名/昵称/手机号'
      })
      wx.setNavigationBarTitle({
        title: '推广掌旅详情' 
      })
      this.getListZL()
    } else if(this.data.pagetype == 2){
      this.setData({
        placeholder:'搜索会员姓名/昵称/手机号'
      })
      wx.setNavigationBarTitle({
        title: '推广客户详情' 
      })
      this.getListKH()
    } else {
      this.setData({
        placeholder:'搜索会员姓名/昵称/手机号'
      })
      wx.setNavigationBarTitle({
        title: '推荐入驻商家详情' 
      })
      this.getListSJ()
    }
  },
  onReady(){
    this.getHeight()
  },
  onShow(){
    
  },
  onHide(){

  },
  onUnload(){

  },
  onPullDownRefresh(){

  },
  onReachBottom(){
    if(this.data.pagetype == 1){
      if(this.data.zlList.length == this.data.zltotalPeople){
        return false
      }
      this.setData({
        page:this.data.page +=1
      })
      this.setData({
        offset:this.data.page*this.data.limit,
      })
      this.getListZL()
    } else if (this.data.pagetype == 2) {
      debugger
      if(this.data.khList.length == this.data.khtotalPeople){
        return false
      }
      this.setData({
        page:this.data.page +=1
      })
      this.setData({
        offset:this.data.page*this.data.limit,
      })
      this.getListKH()
    } else {
      if(this.data.sjList.length == this.data.sjtotalPeople){
        return false
      }
      this.setData({
        page:this.data.page +=1
      })
      this.setData({
        offset:this.data.page*this.data.limit,
      })
      this.getListSJ()
    }
  },
  onShareAppMessage(){
    
  },
})
